#!/bin/bash

# Setup getopt.
getopt_cmd=$(getopt -o cbsva \
            -n $(basename $0) -- "$@") || \
            { echo -e "\nERROR: Getopt failed. Extra args\n";  exit 1;}

eval set -- "$getopt_cmd"

while true; do
    case "$1" in
        -c) CLEAN_BUILD="true";;
        -b) MAKEBOOT="true";;
        -s) MAKESYSTEM="true";;
        -v) MAKEVENDOR="true";;
        -a) MAKEALL="true";;
        --) shift; break;;
    esac
    shift
done

export CCACHE_DIR=../.ccache
export USE_CCACHE=1
prebuilts/misc/linux-x86/ccache/ccache -M 120G
source build/envsetup.sh
lunch ZC08A-wifionlyuserdebug
if [ "$CLEAN_BUILD" = "true" ]; then
    make clean
fi
if [ "$MAKEBOOT" = "true" ]; then
    make bootimage -j8
fi
if [ "$MAKESYSTEM" = "true" ]; then
    make systemimage -j8
fi
if [ "$MAKEVENDOR" = "true" ]; then
    make vendorimage -j8
fi
if [ "$MAKEALL" = "true" ]; then
    make -j8
fi
